package com.sun.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.mapper.InfoMapper;
import com.sun.mapper.RuankeMapper;
import com.sun.mapper.XyhMapper;
import com.sun.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;
import java.util.List;

@Controller
public class RankController {

    @Autowired
    RuankeMapper ruankeMapper;
    @Autowired
    XyhMapper xyhMapper;
    @Autowired
    InfoMapper infoMapper;

    /*
    *
    * 软科排名
    * */
    @RequestMapping("/rank/{pageNo}")
    public Object page(@PathVariable("pageNo") Integer pageNo,
                       @RequestParam(value = "rank",defaultValue = "rank")  String rank,
                       Model model
    ) {
        PageHelper.startPage(pageNo,10);
        List<RuankeRank> list = ruankeMapper.selectAll();
        PageInfo<RuankeRank> page = new PageInfo<>(list,5);
        model.addAttribute("list",page);
        model.addAttribute("rank",rank);
        System.out.println(page);
//        return page;
        return "rank/list";
    }

    @RequestMapping("/rank")
    public String po(@RequestParam(value = "pageNo1",defaultValue = "1") Integer pageNo1,
                     @RequestParam(value = "rank",defaultValue = "rank")  String rank,
                     Model model){
        System.out.println(pageNo1);
        PageHelper.startPage(pageNo1,10);
        List<RuankeRank> list = ruankeMapper.selectAll();
        PageInfo<RuankeRank> page1 = new PageInfo<>(list,5);
        model.addAttribute("list",page1);
        model.addAttribute("rank",rank);
        System.out.println(page1);
        return "rank/list";
    }
    @RequestMapping("/ranks")
    public String select(@RequestParam("name") String name,
//                         @PathVariable("pageNo") Integer pageNo,
                         @RequestParam(value = "rank",defaultValue = "rank")  String rank,
                         Model model){
        List<RuankeRank> list = ruankeMapper.selectData(name);
        PageInfo<RuankeRank> page1 = new PageInfo<>(list, 5);
        model.addAttribute("list", page1);
        model.addAttribute("rank",rank);
        return "rank/list";
    }
    /*
     * 查询软科top10
     * */
    @RequestMapping("/rank/data1")
    @ResponseBody
    public Collection<RuankeRank> selectRuanKeTop10(){
        Collection<RuankeRank> list= ruankeMapper.selectRuanKeTop10();
        System.out.println(list);
        return list ;
    }
    /*
    * 软科排名第一校园指数
    * */
    @RequestMapping("/rank/top1")
    @ResponseBody
    public Collection<Info> selectRuanKeTop1(){
        Collection<Info> list= infoMapper.selectRuanKeTop1();
        System.out.println(list);
        return list ;
    }
    /*
     * 进入可视化界面
     * */
    @RequestMapping("/rank/echarts")
    public String Ecahrts() {
        return "rank/echarts";
    }


    /*
    *
    *
    * 校友会排名
    * */
    @RequestMapping("/xyh_rank/{pageNo}")
    public Object XyhPage(@PathVariable("pageNo") Integer pageNo,
                          @RequestParam(value = "rank",defaultValue = "xyh_rank") String rank,
                       Model model
    ) {
        PageHelper.startPage(pageNo,10);
        List<XyhRank> list = xyhMapper.selectAll();
        PageInfo<XyhRank> page = new PageInfo<>(list,5);
        model.addAttribute("list",page);
        model.addAttribute("rank",rank);
        System.out.println(page);
//        return page;
        return "rank/list";
    }


    @RequestMapping("/xyh_rank")
    public String xyhPo(@RequestParam(value = "pageNo1",defaultValue = "1") Integer pageNo1,
                     @RequestParam(value = "rank",defaultValue = "xyh_rank")  String rank,
                     Model model){
        PageHelper.startPage(pageNo1,10);
        List<XyhRank> list = xyhMapper.selectAll();
        PageInfo<XyhRank> page1 = new PageInfo<>(list,5);
        model.addAttribute("list",page1);
        model.addAttribute("rank",rank);
        System.out.println(page1);
        return "rank/list";
    }

    @RequestMapping("/xyh_ranks")
    public String selectx(@RequestParam("name") String name,
                         @RequestParam(value = "rank",defaultValue = "xyh_rank")  String rank,
                         Model model){
        List<XyhRank> list = xyhMapper.select(name);
        PageInfo<XyhRank> page1 = new PageInfo<>(list, 5);
        model.addAttribute("list", page1);
        model.addAttribute("rank",rank);
        return "rank/list";
    }
    /*
     * 查询校友会top10
     * */
    @RequestMapping("/xyh/data1")
    @ResponseBody
    public Collection<XyhRank> selectXyhTop10(){
        Collection<XyhRank> list= xyhMapper.selectXyhTop10();
        System.out.println(list);
        return list ;
    }
    /*
     * 校友会排名第一校园指数
     * */
    @RequestMapping("/rank/xyhtop1")
    @ResponseBody
    public Collection<Info> selectXyhTop1(){
        Collection<Info> list= infoMapper.selectXyhTop1();
        System.out.println(list);
        return list ;
    }

}
